package com.banmao.algorithm.No401To500.No541;

/**
 *  我的题解
 */
public class Solution1 {

    public String reverseStr(String s, int k) {
        char[] chars = s.toCharArray();

        int i = 0;
        while(i < chars.length) {
            int end = i + k - 1;
            if(end > chars.length - 1) {
                end = chars.length - 1;
            }

            reverse(chars, i, end);

            i += (2 * k);

        }

        return String.valueOf(chars);
    }

    private void reverse(char[] chars, int start, int end) {
        while (start < end) {
            char temp = chars[start];
            chars[start] = chars[end];
            chars[end] = temp;
            start++;
            end--;
        }

    }

}
